#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 200010;
int b[N];
int n, t;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> t;
    while(t --){
        unsigned long long res = 0;
        memset(b, 0, sizeof b);
        cin >> n;
        for(int i = 0; i < n; i++){
            int c;
            cin >> c;
            if(b[c] == 0) b[c] ++;
            else {
                b[c] --;
                res += c;
            }
        }
        cout << res << endl;
    }
    return 0;
}
